#pragma once

#include <QGraphicsItem>

using namespace std;
class Title;
class Path;
class mainClass;
class QGraphicsSceneMouseEvent;
class Container;
class TreeModel;
class SceneView;
class QTreeView;

class Node : public QObject, public QGraphicsItem
{
	Q_OBJECT
	
public:
	Node(SceneView *_parentScene, Container *_source, QPointF _pos, bool _visibleTitle = true,
		double _as = 0, double _ad = 0, double _ms = 0, double _md = 0);
	~Node();

	Container *source;
	Title *title;
	QRectF size;
	QPointF position;
	QList<Path *> pathList;
	TreeModel* model;
	double additive_stochastic, additive_deterministic; 
	double multiplicative_stochastic, multiplicative_deterministic;
	QRectF boundingRect() const;
	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
	void addTitle(Title *_title);
	void addPath(Path *path);
	void setEnabled(bool b);
	void adjust();
	bool enabled(){ return enable; }
	void setAccepted(bool b){ accepted = b; }
	void initModel();
	void setSelectrable(bool s);
protected:
	void mousePressEvent(QGraphicsSceneMouseEvent *event);
	void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
	void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
	QVariant itemChange(GraphicsItemChange change, const QVariant &value);
private:
	SceneView *parentScene;
	void checkPosition(QPointF cPos);
	bool enable;
	bool accepted;
	bool visibleTitle;
private slots:
	void getModelData(QString name, int posX, int posY, bool dispTitle, bool dispValue,
		double _additive_stochastic = 0, double _additive_deterministic = 0, 
		double _multiplicative_stochastic = 0, double _multiplicative_deterministic = 0);
	void updateTree();
signals:
	void setModelData(QString name, int posX, int posY, bool dispTitle, bool dispValue,
		double _additive_stochastic = 0, double _additive_deterministic = 0, 
		double _multiplicative_stochastic = 0, double _multiplicative_deterministic = 0);

};
